<template>
  <div id="app">
    <div class="name">
      <h2>拾忆记事本</h2>
      <p>记录生活点点滴滴,写下生活每一个美好</p>
      <div class="val">
        <input type="text" v-model="val" />
        <button @click="add">确认</button>
      </div>
    </div>
    <div class="top"></div>

    <table>
      <tr>
        <th>序号</th>
        <th>内容</th>
        <th>操作</th>
      </tr>
      <tr v-for="(item,index) in list " :key="index">
        <td>{{index+1}}</td>
        <td>{{item.name}}</td>
        <td>
          <button class="del" @click="del(index)">x</button>
        </td>
      </tr>
    </table>
    <span>暂有{{this.list.length}}条数据</span> &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
    <button
      @click="clear"
    >清空</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      val: "",
      list: [],
    };
  },
  mounted() {},
  methods: {
    add(val) {
      if (this.val == "") {
        alert("内容不能为空");
      } else {
        this.list.push({ name: this.val });
        this.val = "";
      }
    },
    del(index) {
      this.list.splice(index, 1);
    },
    clear() {
      this.list = "";
    },
  },
  computed: {},
};
</script>
<style lang="scss">
p {
  // border: 1px dashed red;
}
table {
  width: 500px;
}
td {
  border-bottom: 1px dashed #000;
  padding: 10px 0 10px 0;
}
input {
  width: 400px;
  height: 20px;
}
.top {
  background-color: #000;
}
.name {
  width: 80%;
  height: 80%;
  background-color: aquamarine;
}
.val{
padding: 0 0 20px 10px;
}
.del{
  border: 0;
  background-color: #fff;
}
</style>
